<%-- 
    Document   : person
    Created on : 2011年9月4日, 下午03:50:39
    Author     : Ming
--%>

<%@page import="unilearn.vo.Person"%>
<%@page import="unilearn.vo.Role"%>
<%@page import="java.util.List"%>
<%@page import="unilearn.bo.PersonManagement"%>
<%@page import="unilearn.bo.PersonManagement"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
            WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
            PersonManagement personMgt = (PersonManagement) context.getBean("personMgt");
            List<Role> roles = personMgt.getAllRole();
            String roleHtmlString = "";
            if ((roles != null) || (!roles.isEmpty())) {
                for (Role r : roles) {
                    roleHtmlString += "<label><input type=\"radio\" name=\"roleId\" value=\"" + r.getId() + "\" alt=\"" + r.getDescription() + "\" />" + r.getName() + "</label>";
                }
            }

            List<Person> ps = personMgt.getAllPersons();
            Person person = ps.get(ps.size() - 1);
        %>
        <form method="post" action="../person.do">
            <p>Create Person</p>
            <input type="hidden" name="action" value="create"/>
            <p><%=roleHtmlString%></p>
            <p>First Name: <input type="text" name="firstName" /></p>
            <p>Last Name: <input type="text" name="lastName" /></p>
            <p>E-mail: <input type="text" name="email" /></p>
            <p>Password: <input type="text" name="password" /></p>
            <p><input type="submit" value="Create"/></p>
        </form>
        <hr />
        <form method="post" action="../person.do">
            <p>Update Person</p>
            <input type="hidden" name="action" value="update"/>
            <input type="hidden" name="id" value="<%=person.getId()%>"/>
            <p><%=roleHtmlString%></p>
            <p>First Name: <input type="text" name="firstName" value="<%=person.getFirstName()%>" /></p>
            <p>Last Name: <input type="text" name="lastName" value="<%=person.getLastName()%>" /></p>
            <p>E-mail: <input type="text" name="email" value="<%=person.getEmail()%>" /></p>
            <p>Password: <input type="text" name="password" value="<%=person.getPassword()%>" /></p>
            <p><input type="submit" value="Update"/></p>
        </form>
    </body>
</html>
